package com.shgx.client;

import com.shgx.grpc.api.*;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

/**
 * @author: guangxush
 * @create: 2019/07/07
 */
public class GRPCClient {
    private static final String host = "localhost";
    private static final int serverPort = 9991;

    public static void main( String[] args ) throws Exception {
        ManagedChannel managedChannel = ManagedChannelBuilder.forAddress( host, serverPort ).usePlaintext().build();
        try {
            RPCDateServiceGrpc.RPCDateServiceBlockingStub rpcDateService = RPCDateServiceGrpc.newBlockingStub( managedChannel );
            RPCDateRequest rpcDateRequest = RPCDateRequest
                    .newBuilder()
                    .setUserName("lingsuzhi")
                    .build();
            RPCDateResponse rpcDateResponse = rpcDateService.getDate( rpcDateRequest );
            System.out.println( rpcDateResponse.getServerDate() );


            RPCDateLszServiceGrpc.RPCDateLszServiceBlockingStub rpcDateLszServiceBlockingStub = RPCDateLszServiceGrpc.newBlockingStub(managedChannel);
            RPCDateLszRequest rpcDateLszRequest = RPCDateLszRequest
                    .newBuilder()
                    .setUserName("lsz")
                    .build();
            RPCDateLszResponse rpcDateLszResponse = rpcDateLszServiceBlockingStub.getDateLsz( rpcDateLszRequest );
            System.out.println( rpcDateLszResponse.getServerDate() );

        } finally {
            managedChannel.shutdown();
        }
    }
}
